import { Component, OnInit, ViewChild } from '@angular/core';
import { STPage, STComponent, STColumn, STChange } from '@delon/abc/st';
import { _HttpClient } from '@delon/theme';
import { NzModalRef } from 'ng-zorro-antd/modal';
import { Api } from 'src/app/shared/api/api';
import { ResponseCode } from 'src/app/shared/response.code';
@Component({
  selector: 'app-system-user-tenant',
  templateUrl: './user-tenant.component.html'
})
export class SystemUserTenantComponent implements OnInit {
  record: any = {};
  params: any = {};
  searchParams: any = {};
  page: any = {
    records: [],
    current: 1,
    total: 0,
    size: 10
  };
  pagination: STPage = {
    front: false,
    pageSizes: [10, 20, 30, 40, 50],
    total: true,
    showSize: true,
    showQuickJumper: true
  };

  @ViewChild('st', { static: true }) st!: STComponent;
  columns: STColumn[] = [
    { title: '序号', type: 'no', width: '50px' },
    { title: '租户名称', index: 'tenantName' }
  ];

  constructor(private modal: NzModalRef, public http: _HttpClient) {}

  ngOnInit() {
    // this.query();
  }

  change(e: STChange) {
    if (e.type === 'pi' || e.type === 'ps') {
      this.params.size = e.ps;
      this.params.current = e.pi;
      // this.query();
    }
  }

  search(event: any) {
    this.searchParams = event;
    // this.query();
  }

  query() {
    const current: number = this.params.current || 1;
    const size: number = this.params.size || 10;
    this.http.get(`${Api.BaseSysTenantApi}page/tenant/${this.record.id}/${current}/${size}`, this.searchParams).subscribe((res: any) => {
      if (res && res.code === ResponseCode.SUCCESS) {
        if (res.data) this.page = res.data;
      }
    });
  }

  close() {
    this.modal.destroy();
  }
}
